<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录日志</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
</head>

<body>
<% include("../layout/loading.html"){} %>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-form-item">
                            <label class="layui-form-label w-auto">所属校区:</label>
                            <div class="layui-input-inline">
                                <select name="schoolId" id="schoolId" lay-verType="tips">
                                    <option value="">请选择</option>
                                    <% for(school in schools) { %>
                                    <option value="${school.id}">${school.schoolName}</option>
                                    <% } %>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">账号：</label>
                        <div class="layui-input-inline mr0">
                            <input id="userName" class="layui-input" type="text" placeholder="请输入账号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">日期：</label>
                        <div class="layui-input-inline">
                            <input id="edtDate" class="layui-input date-icon" type="text" placeholder="请选择日期范围" style="width: 210px"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                        <button id="btnReset" class="layui-btn icon-btn"><i class="layui-icon">&#xe669;</i>重置</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="logTable" lay-filter="logTable"></table>
        </div>
    </div>

</div>

<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var laydate = layui.laydate;

        // 渲染表格
        var insTb = table.render({
            elem: '#logTable',
            url: 'loginRecord/opList',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'userName', title: '账号',width:120},
                {field: 'nickName', title: '用户名',width:120},
                {field: 'operation', title: '操作'},
                {field: 'ipAddress', title: 'IP',width:150},
                // {field: 'device', title: '设备'},
                // {field: 'osName', title: '设备类型'},
                // {field: 'browserType', title: '浏览器'},
                {
                    templet: function (d) {
                        return util.toDateString(d.createdDate);
                    }, title: '登录时间',width:160
                }
            ]]
        });

        // 重置
        $('#btnReset').click(function () {
            $("#schoolId").val("");
            $("#userName").val("");
            $("#edtDate").val("");
            form.render("select");//重新渲染 固定写法
            window.location.reload();
        });

        // 时间范围
        laydate.render({
            elem: '#edtDate',
            range: true,
            theme: 'molv',
            type: 'date'
        });

        // 搜索按钮点击事件
        $('#btnSearch').click(function () {
            var searchDate = $('#edtDate').val().split(' - ');
            var userName = $('#userName').val();
            var schoolId = $('#schoolId').val();
            if(searchDate.length > 1){
                insTb.reload({
                    where: {
                        startDate: searchDate[0] /*+' 00:00:00'*/,
                        endDate: searchDate[1] /*+' 23:59:59'*/,
                        userName: userName,
                        schoolId:schoolId
                    }
                });
            }
            else {
                insTb.reload({
                    where: {
                        schoolId: schoolId,
                        userName: userName,
                        startDate: '',
                        endDate: '',
                    }
                });
            }
        });

    });
</script>

</body>
</html>